<?php

namespace App\Http\Resources;

use App\Models\Category;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\User;

class TaskResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'image' => env('APP_URL') . '/uploads/' . User::where('id', $this->uid)->value('headimgurl'),
            'type' => getDictValue('task_type', $this->type),
            'category' => Category::query()->where('id', $this->category_id)->value('name'),
            'singular' => $this->singular,
            'price' => $this->price,
            'valid_time' => getDictValue('valid_time', $this->valid_time),
            'is_recommend' => $this->is_recommend,
            'is_good' => $this->is_good,
            'status' => getDictValue('task_status', $this->status),
            'created_at' => getDateTime($this->created_at),
        ];
    }
}
